<?php
/*************************************************************************************/
/*                                                                                   */
/*      Thelia	                                                            		 */
/*                                                                                   */
/*      Copyright (c) Octolys Development		                                     */
/*		email : thelia@octolys.fr		        	                             	 */
/*      web : http://www.octolys.fr						   							 */
/*                                                                                   */
/*      This program is free software; you can redistribute it and/or modify         */
/*      it under the terms of the GNU General Public License as published by         */
/*      the Free Software Foundation; either version 2 of the License, or            */
/*      (at your option) any later version.                                          */
/*                                                                                   */
/*      This program is distributed in the hope that it will be useful,              */
/*      but WITHOUT ANY WARRANTY; without even the implied warranty of               */
/*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                */
/*      GNU General Public License for more details.                                 */
/*                                                                                   */
/*      You should have received a copy of the GNU General Public License            */
/*      along with this program; if not, write to the Free Software                  */
/*      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    */
/*                                                                                   */
/*************************************************************************************/
?>
<?php
include_once(realpath(dirname(__FILE__)) . "/../../../classes/PluginsClassiques.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../classes/Commande.class.php");
include_once(realpath(dirname(__FILE__)) . "/../../../fonctions/divers.php");

class Fichierproduit extends PluginsClassiques{

		function Fichierproduit(){
			$this->PluginsClassiques();	
		}
	
		function init(){
			mkdir(realpath(dirname(__FILE__)) . "/../../../client/gfx/photos/persofichier");
		}
		
		function post(){
			include_once(realpath(dirname(__FILE__)) . "/config.php");

			global $action;
			
			if($_FILES['persofichier']['name'] != "") { 
			 if($action == "ajouter"){
				$rEFileTypes = "/^\.(jpg|jpeg|gif|png|doc|pdf){1}$/i"; 
				$safe_filename = preg_replace( array("/\s+/", "/[^-\.\w]+/"), array("_", ""), trim($_FILES['persofichier']['name'])); 
				if(preg_match($rEFileTypes, strrchr($safe_filename, '.')))
				{
	
	 			$nom = genpass(40);
	 			preg_match("`\.(.+)`", $_FILES['persofichier']['name'], $cut);

				$index = $_SESSION['navig']->panier->nbart - 1;
				
				$urlsite = new Variable();
				$urlsite->charger("urlsite");
				$chaine = "<a href='" . $urlsite->valeur . "/client/gfx/photos/persofichier/" . $nom . "." . $cut[1] . "'>" . $nom_lien . "</a>";

				$_SESSION['navig']->panier->tabarticle[$index]->perso[0]->declinaison = $declinaison_fichierprod;
				$_SESSION['navig']->panier->tabarticle[$index]->perso[0]->valeur = $chaine;
				move_uploaded_file($_FILES['persofichier']['tmp_name'], realpath(dirname(__FILE__)) . "/../../../client/gfx/photos/persofichier/$nom" . "." . $cut[1]);
				// copy($_FILES['persofichier']['tmp_name'], realpath(dirname(__FILE__)) . "/../../../client/gfx/photos/persofichier/$nom" . "." . $cut[1]); 
				}
				else	
				{
					echo "Error, your file $safe_filename is not accepted, please send file like jpg|jpeg|gif|png|doc|pdf";
					exit(1);
				}
			}
}

		}
		function destroy(){

		}
	}


?>
